app.controller("z-employee-c", [ '$scope','$rootScope','$z-http','$sce','z-employee-s','z-dictionary-s','z-corporation-s','z-department-s','z-role-s','z-edit-menu-s','z-corporation-s','z-department-s','$filter',
		function($scope,$rootScope,$zhttp,$sce,Service,DictionaryService,CorporationService,DepartmentService,RoleService,MenuService,CorporationService,DepartmentService,$filter) {
		$scope.viewModel = {};
		$scope.viewModel.perPage = "10";
		$scope.viewModel.rowCount = "1";	
		$scope.viewModel.employeeIsSeparated="";
		$scope.viewModel.regionType="";
		$scope.viewModel.employeeNo="";
		$scope.viewModel.roleName="";
		$scope.viewModel.departmentList=[];
		$scope.viewModel.corporationList=[];
		$scope.viewModel.employeeList=[];
		$scope.viewModel.level="";
		$scope.isShow = true;
		// 定义生效时间框内的值，用于检索
		$scope.viewModel.changeEffectiveDate = new Date();
		// 获取当天日期
		$scope.viewModel.effectiveDate = new Date();
		//地区
		$scope.viewModel.regionTypeData=[];
		//下拉多选框长度
		$scope.multiSelectMaxHeight=300;
			
		$scope.editModel = {};
		$scope.editModel.employee= {};
		$scope.editModel.employee.corporationId = null;
		$scope.editModel.employee.findN=0;

		
		//查询页面名称
		MenuService.getMenuByUrl({url:'employee'},
		function(data){	
			$scope.viewModel.menuList=data;
		},function(error) {});
		
		//加载信息
		$scope.viewModel.bindSelectRegionTypeData = function(){
			//查询地区
			DictionaryService.getDictionaryBydicCls({
				dicCls:"7"
			},
			function(data){
				$scope.viewModel.regionTypeData = data;
				//$scope.mulLink($('#eRegionType'),$scope.viewModel.selectRegionTypeData);  
			},function(error) {
				
			});
			
			//查询公司
			CorporationService.getCorporationList({
				fromDate:$scope.viewModel.changeEffectiveDate,
			},
			function(data){
				var site = [];  
		        $.each(data, function(index, values) {  
		            site.push({  
		                label : "("+values.corporationCode+")"+values.corporationName,  
		                value : values.corporationCode  
		            });  
		        });  
		        $('#eCorporation').multiselect('dataprovider',site);
			},function(error) {
				
			});
		};
		$scope.viewModel.bindSelectRegionTypeData();
		
	
		/*******使用为下拉带勾选控件*********/
		//员工级别
		$('#elevel').multiselect({
			includeSelectAllOption: true,
			enableFiltering: true,
			delimiterText: '; ',
            maxHeight: $scope.multiSelectMaxHeight
        });
		//公司
		$('#eCorporation').multiselect({
			includeSelectAllOption: true,
			enableFiltering: true,
			delimiterText: '; ',
            maxHeight: $scope.multiSelectMaxHeight
        });
		//公司选中事件
		$("#eCorporation").change(function(){  
			var value=$(this).val();
		    var data={};
		    data.corporationCodeList=value;
		    data.fromDate = $scope.viewModel.changeEffectiveDate;
		    if(value==null){
		    	var site = [];  
		    	$('#eDepartmentName').multiselect('dataprovider',site);
			    $scope.viewModel.departmentList=[];
		    }else{
		    	//查询部门
			    DepartmentService.getDepartmentListByCorporationCodeList(data,
				function(data){
			    	var site = [];  
			        $.each(data, function(index, values) {  
			            site.push({  
			                label : "("+values.departmentCode+")"+values.departmentName,  
			                value : values.departmentCode  
			            });  
			        });  
			        $('#eDepartmentName').multiselect('dataprovider',site);
				},function(error) {
					
				});
		    }
        });  
		
		//部门
		$('#eDepartmentName').multiselect({
			includeSelectAllOption: true,
			enableFiltering: true,
			delimiterText: '; ',
            maxHeight: $scope.multiSelectMaxHeight
        });
		
		
		//加载权限组数据
		$scope.editModel.privilegeGroupData = function(){
			$scope.editModel.isLoading=true;
			//获取基本信息
			Service.getPrivilegeGroupList({},
			function(data){
				$scope.editModel.privilegeGroupList = data;
				$scope.editModel.isLoading=false;
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.editModel.isLoading=false;
			});
		};
		$scope.editModel.privilegeGroupData();
		
				
		//新增
		$scope.viewModel.add = function(){
			$scope.editModel.title="新增人员";
			$scope.editModel.type = true;
			$scope.isShow = false;
			$scope.editModel.employee={};
			$scope.editModel.employee.roleList=[];
			$scope.editModel.employee.employeeType=1;
			$scope.editModel.employee.employeeCategory=1;
			$scope.editModel.employee.level=1;
			$scope.viewModel.dirty();
			$scope.viewModel.load();	
		};
		//修正
		$scope.viewModel.update=function(employee){
			$scope.editModel.title="修改人员";
			$scope.editModel.type = false;
			$scope.isShow = true;
			$scope.editModel.employee=angular.copy(employee);
			$scope.editModel.employee.findN=0;
			if($scope.editModel.employee.roleList==undefined){
				$scope.editModel.employee.roleList=[];
			}else{
				for(var t=0;t<$scope.editModel.employee.roleList.length;t++){
					$scope.editModel.employee.roleList[t].startDateOpened=false;
					$scope.editModel.employee.roleList[t].endDateOpened=false;
				}
			}
			if(employee.firstDate!=null){
				$scope.editModel.employee.firstDate=new Date(employee.firstDate);
			}
			if(employee.entryDate!=null){
				$scope.editModel.employee.entryDate=new Date(employee.entryDate);
			}
			if(employee.corporationFromDate!=null){
				$scope.editModel.employee.corporationFromDate=new Date(employee.corporationFromDate);
			}
			if(employee.corporationThruDate!=null){
				$scope.editModel.employee.corporationThruDate=new Date(employee.corporationThruDate);
			}
			if(employee.departmentFromDate!=null){
				$scope.editModel.employee.departmentFromDate=new Date(employee.departmentFromDate);
			}
			if(employee.departmentThruDate!=null){
				$scope.editModel.employee.departmentThruDate=new Date(employee.departmentThruDate);
			}
			if(employee.roleFromDate!=null){
				$scope.editModel.employee.roleFromDate=new Date(employee.roleFromDate);
			}
			if(employee.roleThruDate!=null){
				$scope.editModel.employee.roleThruDate=new Date(employee.roleThruDate);
			}
			if(employee.annualLeaveDate!=null){
				$scope.editModel.employee.annualLeaveDate=new Date(employee.annualLeaveDate);
			}
			$scope.viewModel.dirty();
			$scope.viewModel.load();
		};
		
		$scope.viewModel.dirty=function(){
			//验证不能为空
			$scope.editForm.employeeNo.$dirty=false;
			$scope.editForm.chineseName.$dirty=false;
			$scope.editForm.esex.$dirty=false;
			$scope.editForm.firstDate.$dirty=false;
			$scope.editForm.entryDate.$dirty=false;
			$scope.editForm.corporationFromDate.$dirty=false;
			$scope.editForm.departmentFromDate.$dirty=false;
			$scope.editForm.annualLeaveDate.$dirty=false;
			$scope.editForm.regionType.$dirty=false;
			$scope.editForm.userName.$dirty=false;
			$scope.editForm.privilegeGroupId.$dirty=false;
		};
		
		//加载
		$scope.viewModel.load=function(){
			$scope.viewModel.show=true;
		};
		
		//关闭加载
		$scope.viewModel.unLoad=function(){
			$scope.viewModel.show=false;
		};
		
		$scope.viewModel.attendanceState=""       //考勤状态
		var now = new Date();                     //当前日期     
		var nowMonth = now.getMonth();            //当前月     
		var nowYear=$filter('date')(now,'yyyy');  //当前年
		//获取当月开始日期
		var monthStartDate = $filter("date")(new Date(nowYear, nowMonth, 1), "yyyy/MM/dd");
		//获取当前日期
        var dayEndDate= $filter("date")(now, "yyyy/MM/dd");
		$scope.viewModel.requestStartDate=new Date(monthStartDate);  //起止日期
		$scope.viewModel.requestEndDate=new Date(dayEndDate);	  	  //终止日期
		//日期控件
		$scope.viewModel.dateOptions = {
				formatYear: 'yy',
			    startingDay: 1,
			    showWeeks:false
		};
		//日期控件
		$scope.viewModel.format = "yyyy/MM/dd";
		//日期启动开关
		$scope.viewModel.editCorporationFromDateOpnened = false;
		$scope.viewModel.editCorporationThruDateOpnened = false;
		$scope.viewModel.editDepartmenFromDateOpnened = false;
		$scope.viewModel.editDepartmenThruDateOpnened = false;
		$scope.viewModel.editRoleFromDateOpnened = false;
		$scope.viewModel.editRoleThruDateOpnened = false;
		$scope.viewModel.editStartDateOpened = false;
		$scope.viewModel.editEndDateOpened = false;
		$scope.viewModel.editFirstDateOpnened = false;
		$scope.viewModel.editFirstDateOpen = false;
		$scope.viewModel.editEntryDateOpnened = false;
		$scope.viewModel.editEntryDateOpen = false;
		$scope.viewModel.editAnnualLeaveDateOpnened = false;
		$scope.viewModel.editAnnualLeaveDateOpen = false;
		$scope.viewModel.editEmployeeSeparatedDateOpnened = false;
		$scope.viewModel.editEmployeeSeparatedDateOpen = false;

		$scope.viewModel.editEmployeeSeparatedDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editEmployeeSeparatedDateOpnened = !$scope.viewModel.editEmployeeSeparatedDateOpnened;
		};
		$scope.viewModel.editCorporationFromDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editCorporationFromDateOpnened = !$scope.viewModel.editCorporationFromDateOpnened;
		};
		$scope.viewModel.editCorporationThruDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editCorporationThruDateOpnened = !$scope.viewModel.editCorporationThruDateOpnened;
		};
		$scope.viewModel.editDepartmenFromDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editDepartmenFromDateOpnened = !$scope.viewModel.editDepartmenFromDateOpnened;
		};
		$scope.viewModel.editDepartmenThruDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editDepartmenThruDateOpnened = !$scope.viewModel.editDepartmenThruDateOpnened;
		};
		
		
		$scope.viewModel.editRoleFromDateOpen = function($event,role) {
			$event.preventDefault();
			$event.stopPropagation();
			role.startDateOpened= !role.startDateOpened;
		};
		$scope.viewModel.editRoleThruDateOpen = function($event,role) {
			$event.preventDefault();
			$event.stopPropagation();
			role.endDateOpened= !role.endDateOpened;
		};
		
		
		$scope.viewModel.editFirstDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editFirstDateOpnened = !$scope.viewModel.editFirstDateOpnened;
		};
		$scope.viewModel.editEntryDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editEntryDateOpnened = !$scope.viewModel.editEntryDateOpnened;
		};
		$scope.viewModel.editAnnualLeaveDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.editAnnualLeaveDateOpnened = !$scope.viewModel.editAnnualLeaveDateOpnened;
		};
		
		//验证
		$scope.viewModel.requiredForm= function() {
			if (!$scope.editForm.employeeNo.$valid
					|| !$scope.editForm.chineseName.$valid
					|| !$scope.editForm.esex.$valid
					|| !$scope.editForm.firstDate.$valid
					|| !$scope.editForm.entryDate.$valid
					|| !$scope.editForm.annualLeaveDate.$valid
					|| !$scope.editForm.corporationFromDate.$valid
					|| !$scope.editForm.departmentFromDate.$valid
					|| !$scope.editForm.regionType.$valid
					|| !$scope.editForm.privilegeGroupId.$valid
					|| !$scope.editForm.userName.$valid) {
				if(!$scope.editForm.employeeNo.$dirty){
	        		$scope.editForm.employeeNo.$dirty=true;
	        	}
	        	if(!$scope.editForm.chineseName.$dirty){
	        		$scope.editForm.chineseName.$dirty=true;
	        	}
	        	if(!$scope.editForm.esex.$dirty){
	        		$scope.editForm.esex.$dirty=true;
	        	}
	        	if(!$scope.editForm.firstDate.$dirty){
	        		$scope.editForm.firstDate.$dirty=true;
	        	}
	        	if(!$scope.editForm.entryDate.$dirty){
	        		$scope.editForm.entryDate.$dirty=true;
	        	}
	        	if(!$scope.editForm.annualLeaveDate.$dirty){
	        		$scope.editForm.annualLeaveDate.$dirty=true;
	        	}
	        	if(!$scope.editForm.corporationFromDate.$dirty){
	        		$scope.editForm.corporationFromDate.$dirty=true;
	        	}
	        	if(!$scope.editForm.departmentFromDate.$dirty){
	        		$scope.editForm.departmentFromDate.$dirty=true;
	        	}
	        	if(!$scope.editForm.regionType.$dirty){
	        		$scope.editForm.regionType.$dirty=true;
	        	}
	        	if(!$scope.editForm.privilegeGroupId.$dirty){
	        		$scope.editForm.privilegeGroupId.$dirty=true;
	        	}
	        	if(!$scope.editForm.userName.$dirty){
	        		$scope.editForm.userName.$dirty=true;
	        	}
	        	return true;
			}else{
				var sumIsRole=0;
				for(var i=0;$scope.editModel.employee.roleList.length>i;i++){
					if($scope.editModel.employee.roleList[i].isRole==1){
						sumIsRole++;
					}
				}
				//验证公司是否选择
				if($scope.editModel.employee.corporationId==null){
					$rootScope.alertWarning("未选择公司，请选择！");
					return true;
				}
				//验证部门是否选择
				if($scope.editModel.employee.departmentId==null){
					$rootScope.alertWarning("未选择部门，请选择！");
					return true;
				}
				if(sumIsRole>1){
					$rootScope.alertWarning("默认岗位只能唯一，请修改！");
					return true;
				}else if(sumIsRole==0){
					$rootScope.alertWarning("未选择默认岗位，请选择！");
					return true;
				}
				//验证首次工作时间不能大于入职日期
				if($scope.editModel.employee.firstDate>$scope.editModel.employee.entryDate){
					$rootScope.alertWarning("首次工作日期不能超过入职日期，请重新选择！");
					$scope.editForm.firstDate.$invalid=true;
					return true;
				}
				//验证年假可使用日期不能小于入职日期
				if($scope.editModel.employee.annualLeaveDate<$scope.editModel.employee.entryDate){
					$rootScope.alertWarning("年假可使用日期不能小于入职日期，请重新选择！");
					$scope.editForm.annualLeaveDate.$invalid=true;
					return true;
				}
				//验证公司开始日期
				if($scope.editModel.employee.corporationThruDate!=null){
					if($scope.editModel.employee.corporationFromDate>$scope.editModel.employee.corporationThruDate){
						$rootScope.alertWarning("公司开始日期不能大于结束日期，请重新选择！");
						$scope.editForm.corporationFromDate.$invalid=true;
						return true;
					}else{
						$scope.editForm.corporationFromDate.$invalid=false;
					}
				}
				//验证部门开始日期
				if($scope.editModel.employee.departmentThruDate!=null){
					if($scope.editModel.employee.departmentFromDate>$scope.editModel.employee.departmentThruDate){
						$rootScope.alertWarning("部门开始日期不能大于结束日期，请重新选择！");
						$scope.editForm.departmentFromDate.$invalid=true;
						return true;
					}else{
						$scope.editForm.departmentFromDate.$invalid=false;
					}
				}
				//验证岗位开始日期
				if($scope.editModel.employee.roleThruDate!=null){
					/*if($scope.editModel.employee.roleFromDate>$scope.editModel.employee.roleThruDate){
						$rootScope.alertWarning("岗位开始日期不能大于结束日期，请重新选择！");
						$scope.editForm.roleFromDate.$invalid=true;
						return true;
					}else{
						$scope.editForm.roleFromDate.$invalid=false;
					}*/
				}
				$scope.editForm.firstDate.$invalid=false;
	        	return false;
			}
	    };
		
		//保存
		$scope.viewModel.save = function(){
			if($scope.viewModel.requiredForm()){
				return;
			}
			//循环薪资对象设置日期打开状态
			for(var t=0;t<$scope.editModel.employee.roleList.length;t++){
				delete $scope.editModel.employee.roleList[t].startDateOpened;
				delete $scope.editModel.employee.roleList[t].endDateOpened;
			}
			$scope.viewModel.isLoading = true;
			$scope.editModel.employee.fromDate = $scope.viewModel.changeEffectiveDate;
			if($scope.editModel.type){
				Service.saveEmployee($scope.editModel.employee,
						function(data){
							$scope.viewModel.unLoad();
							$scope.viewModel.bindData();
							$rootScope.alertInfo("新增成功。");
							$scope.viewModel.isLoading = false;
						},function(error) {
							$rootScope.alertError(error.fault.message);
							$scope.viewModel.isLoading = false;
						});
			}else{
				Service.updateEmployee($scope.editModel.employee,
						function(data){
							$scope.viewModel.unLoad();
							$scope.viewModel.bindData();
							$rootScope.alertInfo("修改成功。");
							$scope.viewModel.isLoading = false;
						},function(error) {
							$rootScope.alertError(error.fault.message);
							$scope.viewModel.isLoading = false;
						});
			}
		};

		//重置密码
		$scope.viewModel.resetPassWord=function(employee){
			$rootScope.alertConfirm("确定重置密码吗？",function() {
				$scope.viewModel.isLoading=true;
				Service.resetEmployeePassWord({
					employeeId:employee.employeeId
				},function(){
					$scope.viewModel.bindData();
					$scope.viewModel.isLoading=false;
					$rootScope.alertInfo("重置密码成功。");
				},function(error){
					$scope.viewModel.isLoading=false;
					$rootScope.alertError(error.fault.message);
				});
			});
		};
		

		/*****离职管理*****/
		$scope.viewSeparatedModel={};
		$scope.isShow2=true;
		
		//离职日期
		$scope.viewSeparatedModel.employeeSeparatedDate=null;
		$scope.viewSeparatedModel.employeeSeparatedDateOpnened=false;
		$scope.viewSeparatedModel.employee={};
		//是否找N+1
		$scope.viewSeparatedModel.employee.findN2=0;
		
		$scope.viewSeparatedModel.load=function(employee){
			$scope.viewSeparatedModel.employee=angular.copy(employee);
			$scope.viewSeparatedModel.employee.findN2=0;
			$scope.viewSeparatedModel.show=true;
			$scope.isShow2=true;
		};
		
		$scope.viewSeparatedModel.unLoad=function(){
			$scope.viewSeparatedModel.employee={};
			$scope.viewSeparatedModel.employeeSeparatedDate=null;
			$scope.viewSeparatedModel.employeeSeparatedDateOpnened=false;
			$scope.viewSeparatedModel.show=false;
		};
		
		$scope.viewSeparatedModel.employeeSeparatedDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewSeparatedModel.employeeSeparatedDateOpnened = !$scope.viewSeparatedModel.employeeSeparatedDateOpnened;
		};
		
		//验证
		$scope.viewSeparatedModel.requiredForm= function() {
			if (!$scope.separatedForm.employeeSeparatedDate.$valid) {
				if(!$scope.separatedForm.employeeSeparatedDate.$dirty){
	        		$scope.separatedForm.employeeSeparatedDate.$dirty=true;
	        	}
	        	return true;
			}else{
	        	return false;
			}
	    };
		
		//保存
		$scope.viewSeparatedModel.save=function(){
			if($scope.viewSeparatedModel.requiredForm()){
				return;
			}
			$rootScope.alertConfirm("确定离职吗？",function() {
				$scope.viewModel.isLoading=true;
				Service.deleteEmployee({
					employeeId:$scope.viewSeparatedModel.employee.employeeId,
					employeeSeparatedDate:$scope.viewSeparatedModel.employeeSeparatedDate,
					findN:$scope.viewSeparatedModel.employee.findN2
				},function(){
					$scope.viewModel.isLoading=false;
					$rootScope.alertInfo("离职成功。");
					$scope.viewSeparatedModel.unLoad();
					$scope.viewModel.bindData();
				},function(error){
					$scope.viewModel.isLoading=false;
					$rootScope.alertError(error.fault.message);
				});
			});
		};
		
		/*****复职管理*****/
		$scope.viewRevocationdModel={};
		//保存
		$scope.viewRevocationdModel.save=function(employee){
			$rootScope.alertConfirm("确定复职吗？",function() {
				$scope.viewModel.isLoading=true;
				Service.updateEmployeeByRevocation({
					employeeId:employee.employeeId,
					employeeSeparatedDate:employee.employeeSeparatedDate,
				},function(){
					$scope.viewModel.isLoading=false;
					$rootScope.alertInfo("复职成功。");
					$scope.viewModel.bindData();
				},function(error){
					$scope.viewModel.isLoading=false;
					$rootScope.alertError(error.fault.message);
				});
			});
		};
		
		
		
		/*****公司选择*****/
		$scope.viewCorporationModel={};
		$scope.viewCorporationModel.dataList={};
		$scope.viewCorporationModel.corporation={};
		$scope.viewSelectCorporationModel={};
		$scope.viewSelectCorporationModel.show=false;
		$scope.viewCorporationModel.bindData = function(){
			$scope.viewCorporationModel.isLoading=true;
			//获取基本信息
			CorporationService.getCorporationList({
				fromDate:$scope.viewModel.changeEffectiveDate,
			},
			function(data){
				$scope.viewCorporationModel.dataList = data;
				$scope.viewCorporationModel.isLoading=false;
			},function(error) {
				$scope.viewCorporationModel.isLoading=false;
			});
		};
		
		$scope.viewSelectCorporationModel.load=function(){
			$scope.viewSelectCorporationModel.bindCorporationData();
			$scope.viewSelectCorporationModel.show=true;
		};
		//关闭加载
		$scope.viewSelectCorporationModel.unLoad=function(){
			$scope.viewSelectCorporationModel.show=false;
		};
		// 上级部门选择按钮
		$scope.viewCorporationModel.chooseUpde = function(){
			$scope.viewSelectCorporationModel.show=true;
			$scope.viewCorporationModel.title="选择所属公司";
			$scope.viewCorporationModel.bindData();
		}
		$scope.viewCorporationModel.chooseDelete = function(){
			$scope.editModel.employee.corporationId = null;
			$scope.editModel.employee.corporationCode = null;
			$scope.editModel.employee.corporationName = null;
		}
		// 点击选择指定上级部门按钮
		$scope.viewCorporationModel.upCorporation = function(corporation){
			$scope.viewSelectCorporationModel.show=false;
			$scope.viewModel.show=true;
			$scope.editModel.employee.corporationId = corporation.corporationId;
			$scope.editModel.employee.corporationCode = corporation.corporationCode;
			$scope.editModel.employee.corporationName = corporation.corporationName;
		}
		$scope.viewCorporationModel.isInAssignmentArr=function(corporation){
			if($scope.editModel.employee.corporationId == corporation.corporationId){
				return true;
			}
			return false;
		};
		/*****部门选择*****/
		$scope.viewDepartmentModel={};
		$scope.viewDepartmentModel.dataList={};
		$scope.viewDepartmentModel.departmentName="";
		$scope.viewDepartmentModel.department={};
		$scope.viewDepartmentModel.perPage="10";
		$scope.viewDepartmentModel.rowCount="1";
		$scope.viewSelectDepartmentModel={};
		$scope.viewSelectDepartmentModel.show=false;
		$scope.viewDepartmentModel.bindData = function(){
			$scope.viewDepartmentModel.isLoading=true;
			//获取基本信息
			DepartmentService.getDepartmentList({
				corporationCode:$scope.editModel.employee.corporationCode,
				pageNo:$scope.viewDepartmentModel.rowCount,
				pageCount:$scope.viewDepartmentModel.perPage,
				departmentName:$scope.viewDepartmentModel.departmentName,
				fromDate:$scope.viewModel.changeEffectiveDate,
			},
			function(data){
				$scope.viewDepartmentModel.dataList = data.departmentBeanList;
				$scope.viewDepartmentModel.totalData = data.pageTotal;
				$scope.viewDepartmentModel.isLoading=false;
			},function(error) {
				$scope.viewDepartmentModel.isLoading=false;
			});
		};
		
		$scope.viewSelectDepartmentModel.load=function(){
			$scope.viewSelectDepartmentModel.bindData();
			$scope.viewSelectDepartmentModel.show=true;
		};
		//关闭加载
		$scope.viewSelectDepartmentModel.unLoad=function(){
			$scope.viewSelectDepartmentModel.show=false;
		};
		// 上级部门选择按钮
		$scope.viewDepartmentModel.chooseUpde = function(){
			if($scope.editModel.employee.corporationId == null){
				$rootScope.alertError("请先选择公司!");
			}else{
			$scope.viewSelectDepartmentModel.show=true;
			$scope.viewDepartmentModel.title="选择所属部门";
			$scope.viewDepartmentModel.bindData();
			}
		}
		$scope.viewDepartmentModel.chooseDelete = function(){
			$scope.editModel.employee.departmentId = null;
			$scope.editModel.employee.departmentCode = null;
			$scope.editModel.employee.departmentName = null;
		}
		// 点击选择指定上级部门按钮
		$scope.viewDepartmentModel.upDepartment = function(department){
			$scope.viewSelectDepartmentModel.show=false;
			$scope.viewDepartmentModel.show=true;
			$scope.editModel.employee.departmentId = department.departmentId;
			$scope.editModel.employee.departmentCode = department.departmentCode;
			$scope.editModel.employee.departmentName = department.departmentName;
		}
		//是否选中
		$scope.viewDepartmentModel.isInAssignmentArr=function(department){
			if($scope.editModel.employee.departmentId == department.departmentId){
				return true;
			}
			return false;
		};
		/*****岗位选择*****/
		$scope.viewRoleModel={};
		$scope.viewRoleModel.dataList={};
		$scope.viewRoleModel.perPage="10";
		$scope.viewRoleModel.rowCount="1";
		$scope.viewRoleModel.role={};
		$scope.viewRoleModel.roleName="";
		$scope.viewSelectRoleModel={};
		$scope.viewSelectRoleModel.show=false;
		
		$scope.viewRoleModel.bindCorporationData = function(){
			
			$scope.viewCorporationModel.isLoading=true;
			//获取基本信息
			CorporationService.getCorporationList({
				fromDate:$scope.viewModel.changeEffectiveDate,
			},
			function(data){
				$scope.viewRoleModel.dataCorporationList = data;
				$scope.viewRoleModel.isLoading=false;
			},function(error) {
				$scope.viewRoleModel.isLoading=false;
			});
		};
		$scope.viewRoleModel.bindCorporationData();
		$scope.viewRoleModel.departmentRole = function(){
			$scope.viewRoleModel.departmentId="";
			$scope.viewRoleModel.isLoading=true;
			//获取基本信息
			DepartmentService.getDepartmentListByCorporationCodeList({
				corporationId:$scope.viewRoleModel.corporationId,
				fromDate:$scope.viewModel.changeEffectiveDate,
			},
			function(data){
				$scope.viewRoleModel.dataDepartmentList = data;
				$scope.viewRoleModel.isLoading=false;
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.viewRoleModel.isLoading=false;
			});
		};
		
		$scope.viewRoleModel.bindData = function(){
			$scope.viewRoleModel.isLoading=true;
			//获取基本信息
			RoleService.getRoleList({
				pageNo:$scope.viewRoleModel.rowCount,
				pageCount:$scope.viewRoleModel.perPage,
				roleName:$scope.viewRoleModel.roleName,
				departmentId:$scope.viewRoleModel.departmentId,
				fromDate:$scope.viewModel.changeEffectiveDate,
				
			},
			function(data){
				$scope.viewRoleModel.dataList = data.roleBeanList;
				$scope.viewRoleModel.totalData = data.pageTotal;
				$scope.viewRoleModel.isLoading=false;
				
			},function(error) {
				$scope.viewRoleModel.isLoading=false;
			});
			
		};
		$scope.viewSelectRoleModel.load=function(){
			$scope.viewSelectRoleModel.bindRoleData();
			$scope.viewRoleModel.departmentRole();
			$scope.viewSelectRoleModel.show=true;
		};
		//关闭加载
		$scope.viewSelectRoleModel.unLoad=function(){
			$scope.viewSelectRoleModel.show=false;
		};
		// 上级部门选择按钮
		$scope.viewRoleModel.chooseUpde = function(){
				$scope.viewSelectRoleModel.show=true;
				$scope.viewRoleModel.title="选择岗位";
				$scope.viewRoleModel.departmentRole();
				$scope.viewRoleModel.bindData();

		}
		$scope.viewRoleModel.chooseDelete = function(){
			$scope.editModel.employee.roleId = null;
			$scope.editModel.employee.roleCode = null;
			$scope.editModel.employee.roleName = null;
		}
		// 点击选择指定上级部门按钮
		$scope.viewRoleModel.upRole = function(role){
			$scope.viewSelectRoleModel.show=false;
			$scope.viewRoleModel.show=true;
			$scope.editModel.employee.roleList.push(role);
		}
		$scope.viewRoleModel.isInAssignmentArr=function(role){
			if($scope.editModel.employee.roleList!=null){
				for(var i=0;$scope.editModel.employee.roleList.length>i;i++){
					if($scope.editModel.employee.roleList[i].roleId == role.roleId){
						return true;
					}
				}
			}
			return false;
		};
		$scope.viewRoleModel.delRole=function(role){
			$rootScope.alertConfirm("确定删除吗？",function() {
				for(var i = 0; i < $scope.editModel.employee.roleList.length; i++){
					if($scope.editModel.employee.roleList[i].roleId == role.roleId){
						$scope.editModel.employee.roleList.splice(i,1);
					}
				}
			});
		};
		$scope.viewModel.effectiveDateClose=function(){
	    	if($scope.viewModel.radioValue==3){
	    		
	    	}else{
	    		$scope.viewModel.effectiveDate=null;
	    	}
	    }

		//日期控件
		$scope.viewModel.dateOptions = {
				formatYear: 'yy',
			    startingDay: 1,
			    showWeeks:false
		};
		//日期控件
		$scope.viewModel.format = "yyyy/MM/dd";
		//日期启动开关
		$scope.viewModel.effectiveDateOpen = false;
		$scope.viewModel.effectiveDateOpnened = false;
		$scope.viewModel.effectiveDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.effectiveDateOpnened = !$scope.viewModel.effectiveDateOpnened;

			
		};
		//加载考勤状态数据
		$scope.viewModel.bindData = function(changeEffectiveDate){
			$scope.viewModel.employeeList=[];
			if($scope.viewModel.employeeNo!=null){
				var employeeNoData = $scope.viewModel.employeeNo.split("\n");
				for(var i=0;i<employeeNoData.length;i++){
					$scope.viewModel.employeeList.push(employeeNoData[i]);
				}
			}
			if(changeEffectiveDate == 1){
				$scope.viewModel.changeEffectiveDate = $scope.viewModel.effectiveDate;
			}
			$scope.viewModel.isLoading=true;
			//获取基本信息
			Service.getEmployeeList({
				employeeIsSeparated:$scope.viewModel.employeeIsSeparated,
				regionType:$scope.viewModel.regionType,
				employeeList:$scope.viewModel.employeeList,
				departmentList:$scope.viewModel.departmentList,
				corporationList:$scope.viewModel.corporationList,
				employeeLevelList:$scope.viewModel.employeeLevelList,
				fromDate:$scope.viewModel.effectiveDate,
				perPage:$scope.viewModel.rowCount,
				rowCount:$scope.viewModel.perPage
			},
			function(data){
				$scope.viewModel.dataList = data.employeeBeanList;
				$scope.viewModel.totalData = data.pageTotal;
				$scope.viewModel.isLoading=false;
			},function(error) {
				$scope.viewModel.isLoading=false;
			});
		};
		$scope.viewModel.bindData();
		

		/** ***批量离职**** */
		$scope.viewEmployeeImportIsSeparatedModel = {};
		$scope.viewEmployeeImportIsSeparatedModel.attachmentId = null;
		$scope.viewEmployeeImportIsSeparatedModel.messageHideType = false;
		$scope.viewEmployeeImportIsSeparatedModel.successHideType = false;
		$scope.viewEmployeeImportIsSeparatedModel.message = null;
		$scope.viewEmployeeImportIsSeparatedModel.isArray = false;

		$scope.viewEmployeeImportIsSeparatedModel.Load = function() {
			$scope.viewEmployeeImportIsSeparatedModel.show = true;
		};

		$scope.viewEmployeeImportIsSeparatedModel.unLoad = function() {
			$scope.viewEmployeeImportIsSeparatedModel.show = false;
		};
		
		 $scope.viewEmployeeImportIsSeparatedModel.getTemplate = function () {
	            $rootScope.isLoading = true;
	            Service.getTemplateUrl(function (data) {
	                $rootScope.isLoading = false;
	                window.location.href       = data;
	            }, function () {
	                $rootScope.isLoading = false;
	                //$rootScope.alertError("系统错误!");
	                $scope.viewEmployeeImportIsSeparatedModel.messageHideType=true;
	                $scope.viewEmployeeImportIsSeparatedModel.message="系统错误";
	                $scope.viewEmployeeImportIsSeparatedModel.isArray=false;
	            });
	        };
	        
	        $scope.viewEmployeeImportIsSeparatedModel.fileUploadComplete    = function (data) {
	            $scope.viewEmployeeImportIsSeparatedModel.messageHideType=false;
	            $scope.viewEmployeeImportIsSeparatedModel.successHideType=false;
	            var dataList=data;
	            if (dataList[0]['attachment'] != null) {
	                $scope.$apply(function () {
	                    $scope.viewEmployeeImportIsSeparatedModel.attachmentId = dataList[0]['attachment']['attachmentId'];
	                    $scope.viewEmployeeImportIsSeparatedModel.save();
	                });
	            }
	        };
	        
	        $scope.viewEmployeeImportIsSeparatedModel.save = function () {
	            var str="确认是否离职人员导入！";
	            $rootScope.alertConfirm(str,
	                function() {
	                    if ($scope.viewEmployeeImportIsSeparatedModel.attachmentId != null) {
	                        $rootScope.isLoading = true;
	                        Service.importEmployeeIsSeparated({
	                            attachmentId: $scope.viewEmployeeImportIsSeparatedModel.attachmentId,
	                           }, function (data) {
	                            $rootScope.isLoading = false;
	                            $rootScope.alertInfo("离职员工信息导入成功");
	                            $scope.viewEmployeeImportIsSeparatedsModel.unload();
	                        }, function (data) {
	                            if (angular.isArray(data['fault'])) {
	                                var faultMessage = [data['fault'][0]['message']].concat(data['fault'][0]['errorData']);
	                                $rootScope.alertError(faultMessage);
	                            } else {
	                                $scope.viewEmployeeImportIsSeparatedModel.message=data['fault']['message'];
	                                $rootScope.alertError(data['fault']['message']);
	                            }
	                            $rootScope.isLoading = false;
	                        });
	                    } else {
	                        $rootScope.alertError("请先上传文件!");
	                    }
	                });
	        };
		
		
} ]);